package com.sskj.bibi.ui.activity;


import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.bibi.R;
import com.sskj.bibi.R2;
import com.sskj.bibi.bean.RecordDetailBean;
import com.sskj.bibi.presenter.RecordDetailActivityPresenter;
import com.sskj.common.base.App;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.enums.BuySellEnum;
import com.sskj.lib.util.CoinUtil;

import butterknife.BindView;

/**
 * 成交明细
 */
@Route(path = RConfig.BIBI_RECORD_DETAIL)
public class RecordDetailActivity extends BaseActivity<RecordDetailActivityPresenter> {
    @BindView(R2.id.tvType)
    TextView tvType;
    @BindView(R2.id.tvCoin)
    TextView tvCoin;
    @BindView(R2.id.tvAll)
    TextView tvAll;
    @BindView(R2.id.tvPrice)
    TextView tvPrice;
    @BindView(R2.id.tvNum)
    TextView tvNum;
    @BindView(R2.id.tvFee)
    TextView tvFee;
    @BindView(R2.id.tvTimeDown)
    TextView tvTimeDown;
    @BindView(R2.id.tvPriceDown)
    TextView tvPriceDown;
    @BindView(R2.id.tvNumDown)
    TextView tvNumDown;
    @BindView(R2.id.tvFeeDown)
    TextView tvFeeDown;
    @Autowired
    String id;
    @Autowired
    String tradeType;
    @BindView(R2.id.tvAllTitle)
    TextView tvAllTitle;
    @BindView(R2.id.tvPriceTitle)
    TextView tvPriceTitle;
    @BindView(R2.id.tvNumTitle)
    TextView tvNumTitle;
    @BindView(R2.id.tvFeeTitle)
    TextView tvFeeTitle;

    @Override
    protected int getLayoutId() {
        return R.layout.bibi_activity_record_detail;
    }

    @Override
    public RecordDetailActivityPresenter getPresenter() {
        return new RecordDetailActivityPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        setTitle("成交明细");
    }

    @Override
    protected void initData() {
        mPresenter.getData(id, tradeType);
    }

    public void updateUI(RecordDetailBean data) {
        tvAll.setText(CoinUtil.keepCoinPrice(data.getStockCode(), data.getTotalPrice()));
        tvPrice.setText(CoinUtil.keepCoinPrice(data.getStockCode(), data.getDealPrice()));
        tvNum.setText(CoinUtil.keepCoinNum(data.getStockCode(), data.getDealsRemainNum()));
        tvType.setText(BuySellEnum.getByType(tradeType).getTitle());
        tvType.setTextColor(ContextCompat.getColor(App.INSTANCE, BuySellEnum.getByType(tradeType).getColorRes()));
        tvCoin.setText(data.getStockCode());
        tvFee.setText(CoinUtil.keepCoinPrice(data.getStockCode(), data.getFee()));
        if (tradeType.equals("1")) {
            tvFeeDown.setText(CoinUtil.keepCoinNum(data.getStockCode(),data.getFee()) + " " + data.getRCode());
        } else {
            tvFeeDown.setText(CoinUtil.keepCoinNum(data.getStockCode(),data.getFee()) + " " + data.getRCode());

        }
        tvTimeDown.setText(data.getDealTime());
        tvNumDown.setText(data.getDealsRemainNum() + " " + data.getLCode());
        tvPriceDown.setText(CoinUtil.keepCoinPrice(data.getStockCode(), data.getDealPrice()) + " " + data.getRCode());

        tvAllTitle.setText(String.format("成交总额(%s)", data.getRCode()));
        if (tradeType.equals("1")) {
            tvFeeTitle.setText(String.format("手续费(%s)", data.getRCode()));
        } else {
            tvFeeTitle.setText(String.format("手续费(%s)", data.getRCode()));

        }
        tvPriceTitle.setText(String.format("成交均价(%s)", data.getRCode()));
        tvNumTitle.setText(String.format("成交数量(%s)", data.getLCode()));

    }


}
